package Server.Sessions;

import java.util.LinkedList;

import shared.Messages.Message;

public class OutboundMessages {
	private LinkedList<Message> messages = new LinkedList<Message>();

	public synchronized void addMessage(Message s) {
		getMessages().add(s);
		this.notifyAll();
	}

	public synchronized Message getMessage() { 
		try {
			while (getMessages().isEmpty())
				this.wait(); 
		} catch (InterruptedException e) {
			System.out.println("Wait katkestatud!");
		}

		Message s = getMessages().getFirst();
		getMessages().removeFirst();
		return s;
	}

	/**
	 * @param messages the messages to set
	 */
	public void setMessages(LinkedList<Message> messages) {
		this.messages = messages;
	}

	/**
	 * @return the messages
	 */
	public LinkedList<Message> getMessages() {
		return messages;
	}
}